﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace SuperCaptcha.Mvc.Processor
{
    internal static class ProcessorExtensions
    {
        internal static string GetBase64String(this Bitmap bitmap)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Png);
                byte[] result = stream.ToArray();
                return Convert.ToBase64String(result);
            }
        }

        internal static string GetBase64String(this Stream imageStream)
        {
            using (BinaryReader reader = new BinaryReader(imageStream))
            {
                byte[] result = reader.ReadBytes((int)imageStream.Length);
                return Convert.ToBase64String(result);
            }
        }
    }
}
